﻿using System;
using System.Collections.Generic;
using System.Text;
using CMN.DAL;
using CMN.Entity;
using System.Data;
using System.Data.Common;
namespace CMN.BLL
{
    public class BLLHelper
    {

        #region 当前数据库类型
        /// <summary>
        /// 返回数据库类型字符串形式
        /// </summary>
        /// <returns></returns>
        public  string GetDBType()
        {
            return DALHelper.CMNHelper.DatabaseType.ToString();
        }

        public  DBUtility.DBHelper GetDalHelper()
        {
            return DALHelper.CMNHelper;
        }
        #endregion 

        #region 返回查询的字段值
        /// <summary>
        /// 返回查询的字段值
        /// </summary>
        /// <param name="sql">执行的语句</param>
        /// <returns>字符串类型</returns>
        public  string ExecuteScalar(string sql)
        {
            object obj = DALHelper.CMNHelper.ExecuteScalar(CommandType.Text, sql, null);
            if (obj == null)
            {
                return "";
            }
            else
            {
                return obj.ToString();
            }
        }
        #endregion

        #region 返回查询的字段值
        /// <summary>
        /// 返回查询的结果
        /// </summary>
        /// <param name="sql">执行的语句</param>
        /// <returns>字符串类型</returns>
        public DataTable ExecuteQuery(string sql)
        {
            DataTable dt = DALHelper.CMNHelper.ExecuteQuery(CommandType.Text, sql, null);
            return dt;
        }
        #endregion

        #region 构造sql语句
        /// <summary>
        /// 获取分页SQL
        /// </summary>
        /// <param name="qp">查询条件类</param>
        /// <returns></returns>
        public  string GetPagerSQL(QueryParam qp)
        {
            return DALHelper.CMNHelper.GetPagerSQL(qp);
        }

        /// <summary>
        /// 时间转sql语句
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public  string GetSqlDateTime(DateTime dt)
        {
            return DALHelper.CMNHelper.GetSqlDateTime(dt);
        }
        #endregion

        #region 更新字段方法
        /// <summary>
        /// 更新数据库字段
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="TableFiledsValue">更新字段和值</param>
        /// <param name="Where">更新条件</param>
        /// <returns></returns>
        public  int Update(string table, string TableFiledsValue, string Where)
        {
            return DALHelper.CMNHelper.ExecuteNonQuery(CommandType.Text, string.Concat("update ", table, " set ", TableFiledsValue, " where ", Where), null);

        }

        #endregion

      
 
 

    }
}
